package time;

import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class LocalDateTest {

    @Test
    public void of() {
//        LocalDate date = LocalDate.of(2019, 12, 29);
//        LocalDate date = LocalDate.of(2019, Month.DECEMBER, 29);
        LocalDate date = LocalDate.now();

        System.out.println(date);
        System.out.println(date.getYear());
        System.out.println(date.getMonthValue());
        System.out.println(date.getMonth());
        System.out.println(date.getDayOfYear());
        System.out.println(date.getDayOfMonth());
        System.out.println(date.getDayOfWeek());

        LocalTime time = LocalTime.of(23, 59, 59);
        System.out.println(date.atTime(time)); //和LocalTime组合一个LocateDateTime

        System.out.println(date.format(DateTimeFormatter.ISO_DATE));
        System.out.println(date.format(DateTimeFormatter.BASIC_ISO_DATE));
        System.out.println(date.format(DateTimeFormatter.ISO_LOCAL_DATE));
    }

    /**
     * 绝对修改日期
     */
    @Test
    public void with() {
        LocalDate date = LocalDate.now();
        LocalDate date2 = date.withYear(2022); //修改年份
        System.out.println(date2);

        LocalDate date3 = date.withMonth(12); //修改月份
        System.out.println(date3);

        LocalDate date4 = date.withDayOfMonth(31); //修改天数
        System.out.println(date4);
    }

    /**
     * 相对值修改
     */
    @Test
    public void plusMinus() {
        LocalDate date = LocalDate.now();
//        LocalDate date2 = date.plusYears(1);
        LocalDate date2 = date.minusYears(1);
        System.out.println(date2);

//        LocalDate date3 = date.plusMonths(10);
        LocalDate date3 = date.minusMonths(10);
        System.out.println(date3);

//        LocalDate date4 = date.plusDays(30);
        LocalDate date4 = date.minusDays(30);
        System.out.println(date4);
    }
}
